package com.demo;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

/**
 * @Auther: Code
 * @Date: 2018/9/9 18:02
 * @Description: 批量重命名文件
 */
public class Dom4jReader {

    public static void main(String[] args) {
        //1.获取dom4j解析对象
        SAXReader reader = new SAXReader();

        //2.获取要解析的xml文件
        try {
            Document document = reader.read(new File("C:\\Users\\mifei\\Documents\\WeChat Files\\mefly521\\FileStorage\\File\\2021-09\\计算工具\\jgtx2.xml"));
            //3.获取根标签
            Element rootElement = document.getRootElement();

            getEachElement(rootElement);


        } catch (DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void getEachElement(Element element) {
        if (element.getName().equals("QY")){
            //System.out.print(element.getName());
            System.out.print(element.getText());
            System.out.print(",");
        }
        if (element.getName().equals("SZFW")){
            //System.out.print(element.getName());
            System.out.print(element.getText());
            System.out.println("");
        }

        List<Element> elements = element.elements();
        if (elements!=null) {
            for (Element element2 : elements) {
                getEachElement(element2);
            }
        }
    }
}